#[cfg(test)]
mod tests {
    use c2rust_output::arraylist::ArrayList;

    #[test]
    fn test_new() {
        let list: ArrayList<i32> = ArrayList::new(10);
        assert_eq!(list.length, 0);
        assert_eq!(list.data.capacity(), 10);
    }

    #[test]
    fn test_append() {
        let mut list = ArrayList::new(0);
        assert!(list.append(1));
        assert!(list.append(2));
        assert!(list.append(3));
        assert_eq!(list.length, 3);
        assert_eq!(list.data, vec![1, 2, 3]);
    }

    #[test]
    fn test_prepend() {
        let mut list = ArrayList::new(0);
        assert!(list.append(1));
        assert!(list.append(2));
        assert!(list.append(3));
        assert_eq!(list.length, 3);
        assert_eq!(list.data, vec![1, 2, 3]);
    }

    #[test]
    fn test_remove() {
        let mut list = ArrayList::new(0);
        assert!(list.append(1));
        assert!(list.append(2));
        assert!(list.append(3));
        list.remove(1);
        assert_eq!(list.length, 2);
        assert_eq!(list.data, vec![1, 3]);
    }

    #[test]
    fn test_remove_range() {
        let mut list = ArrayList::new(0);
        assert!(list.append(1));
        assert!(list.append(2));
        assert!(list.append(3));
        assert!(list.append(4));
        list.remove_range(1, 2);
        assert_eq!(list.length, 2);
        assert_eq!(list.data, vec![1, 4]);
    }

    #[test]
    fn test_insert() {
        let mut list = ArrayList::new(0);
        assert!(list.append(1));
        assert!(list.append(3));

        assert!(list.insert(1, 2));
        assert_eq!(list.length, 3);
        assert_eq!(list.data, vec![1, 2, 3]);
    }

    #[test]
    fn test_index_of() {
        let mut list = ArrayList::new(0);
        assert!(list.append(1));
        assert!(list.append(2));
        assert!(list.append(3));
        let index = list.index_of(|&x| x == 2);
        assert_eq!(index, 1);
    }

    #[test]
    fn test_clear() {
        let mut list = ArrayList::new(0);
        assert!(list.append(1));
        assert!(list.append(2));
        list.clear();
        assert_eq!(list.length, 0);
        assert_eq!(list.data.len(), 0);
    }

    #[test]
    fn test_sort() {
        let mut list = ArrayList::new(0);
        assert!(list.append(1));
        assert!(list.append(3));
        assert!(list.append(2));
        list.sort(|a, b| a.cmp(b));
        assert_eq!(list.length, 3);
        assert_eq!(list.data, vec![1, 2, 3]);
    }
}